rest-module.js ➔ restModule   B
last analyzed

Complexity

Conditions 6

Size

Total Lines 30
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 30
rs 8.6666
c 0
b 0
f 0
cc 6
1
// formToObject
2
// Rest
3
function restModule(modulename, classname_prefix, domain, restfile, error, success) {
4
5
    if (classname_prefix === undefined || classname_prefix.length < 1) {
6
        classname_prefix = 'module-';
7
    }
8
9
    if (domain === undefined || domain.length < 1) {
10
        domain = '/visitor/';
11
    }
12
13
    if (restfile === undefined || restfile.length < 1) {
14
        restfile = '/php/index.php';
15
    }
16
17
    var url = domain + modulename + restfile;
18
19
    var rest_form = new Rest(url, '?', error, success);
0 ignored issues
show
Bug introduced by
The variable Rest seems to be never declared. If this is a global, consider adding a /** global: Rest */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
20
21
22
    // var forms = document.getElementsByTagName('form');
23
    var testElements = document.getElementsByClassName(classname_prefix + modulename);
24
    var forms = Array.prototype.filter.call(testElements, function (testElement) {
25
        return testElement.nodeName === 'FORM';
26
    });
27
28
    // console.log(forms);
29
    for (var i = 0; i < forms.length; i++) {
30
        formData(forms[i], rest_form, error, success);
31
    }
32
}
33
34
function formData(form, rest_form, error, success) {
0 ignored issues
show
Unused Code introduced by
The parameter success is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter error is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
35
    console.log(form);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
36
37
    form.addEventListener("submit", function (event) {
38
        console.log(this);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
39
40
        var data = formToObject(this);
41
        var method = data.method;
42
        delete data.method;
43
        delete data.submit;
44
45
        console.log(method);
46
47
        rest_form.byMethod(method, data);
48
        console.log(data);
49
50
        event.preventDefault();
51
    });
52
}
53